<?

	include_once("cmsConfig.php");

	class GripLockOrderContainer extends CmsOrderContainer {
		
		function GripLockOrderContainer(){
			parent::CmsOrderContainer();
			
			$this->keys = array_merge_recursive(
				array(				
					 EXTRACT_STRING => array(
					 	"hearAboutUs",
					 	"state",
					 	"zip",
					 	"bikeModel",
					 	"currency"
					 ),
				),
				array(
					EXTRACT_BOOLEAN => array("termsAgree")
				),
				$this->keys
			);			
			
			$this->dataModelKeyMapping = 
				array_merge(
					$this->dataModelKeyMapping,
					array(	
						
						 "hearAboutUs"=>"extra5",
						 "state" => "extra6",
						 "zip" => "extra7",
						 "bikeModel"=>"extra8",
						 "currency" => "extra9"
						 //termsAgree // dont need to keep this.. if the purchase goes ahead. then its all good					
				));		
				
			$this->requiredKeys = array_merge(
				array("termsAgree","zip"),
				$this->requiredKeys
			);		
			
		}
		
		function totalPrice(){
			
			$totalPrice = 0;
			
			$orderPrice = $this->valueForKey('price');
			
			$totalPrice = $totalPrice + $orderPrice;
			
			$shippingPrice = $this->valueForKey('shippingPrice');
			if(is_numeric($shippingPrice) && $shippingPrice > 0 )
				$totalPrice =  $totalPrice + $shippingPrice;
				
			$this->log($this->id()." Order Price '". $orderPrice ."'.");
			$this->log($this->id()." Shipping Price '". $shippingPrice ."'.");
			$this->log($this->id()." Total Price '". $totalPrice ."'.");
			
			return $totalPrice;
		}		

		function shippingPrice() {
			return 0;
		}
		
		
		function price(){
			$price =0;
			foreach ($this->valueForKey('orderItems') as $oi) {
				$price +=  ($oi->valueForKey('price') * $oi->valueForKey('quantity'));
			}
			return $price;
		}
		
		function cancelOrder($authInfo, &$db) {
			$this->takeValueForKey(array(), 'orderItems');
			$this->log("Order '". $this->id ."' has been canceld.");
		}
	}